package com.chenfubing.ps.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chenfubing.ps.entity.Space;
import com.chenfubing.ps.service.ISpaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author chenfubing
 * @since 2020-05-05
 */
@RestController
@RequestMapping("/space")
public class SpaceController {

    @Autowired
    private ISpaceService iSpaceService;

    /**
     * 添加车位
     *
     * @param space
     */
    @PostMapping("/addSpace")
    public void addSpace(@RequestBody Space space) {
        iSpaceService.addSpace(space);
    }

    /**
     * 删除车位
     *
     * @param id
     */
    @GetMapping("/deleteSpace")
    public void deleteSpace(int id) {
        iSpaceService.deleteSpace(id);
    }

    /**
     * 获取已用车位分页
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/getSpacePage")
    public Page<Space> getSpacePage(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize) {
        return iSpaceService.getSpacePage(pageNum, pageSize);
    }

    /**
     * 获得剩余车位个数
     *
     * @return
     */
    @GetMapping("/getRemainingSpace")
    public Integer getRemainingSpace() {
        return iSpaceService.getRemainingSpace();
    }

}
